var express = require('express');
var md5=require("md5")
var router = express.Router();
//引入数据库包
var db = require('../../../routes/db.js');
console.log(__dirname);
console.log(__filename);
/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('./admin/login/login', {title: '', message: ''});
});
/**
 * 登录校验
 * */
router.post('/check', function (req, res) {
    var username = req.body.username;
    var password = req.body.password;
    var pass=md5(password);//引入md5加密规则
    console.log(pass);
    // console.log(username);
    // console.log(password);
    var sql = "select username from person where username='" + username + "' and password='" + pass + "'";
    console.log(sql)
    db.query(sql, function (err, rows) {
        console.log(rows)
        var str = JSON.stringify(rows).replace(/},{/g, '},\n{');
        console.log(str);
        for (var le in rows) {
            console.log(rows[le].username)
            if ((rows[le].username) == username) {
                console.log("账号和密码都是可以的")
                res.redirect('/index');
               } else {
                console.log("不可以")
            }
        }
    })
});
module.exports = router;
